%
% N choose M example for TopLog
%

int_division(N, M, R):-
  M\=0, 
  0 is N mod M,
  R is N//M.

minus(A, B, C):-
  A>=B, C is A-B.

mult(A, B, C):-
  C is A*B.

fact(0, 1).
fact(N, R):-
  N>0,
  N1 is N-1,
  fact(N1,R1),
  R is R1*N.

% The correct definition is:
%     nchoosem(N, M, R):-
%         fact(N, FN),
%         fact(M, FM),
%         minus(N,M,T1),
%         fact(T1, FT),
%         mult(FM,FT,T2),
%         int_division(FN,T2,R).

:-modeh(nchoosem(+int,+int,-int)).
:-modeb(3, fact(+int, -int)). 
:-modeb(minus(+int,+int,-int)).
:-modeb(mult(+int,+int, -int), commutative).
:-modeb(int_division(+int,+int,-int)).

:-set(example_inflation, 10).
:-set(maximum_literals_in_hypothesis, 6).

example(nchoosem(3,1,3), 1).
example(nchoosem(4,3,4), 1).
example(nchoosem(6,3,20), 1).
